from .log import log

def InitUi():
  global fixed
  global window

  window = hildon.Window()
  window.fullscreen()
  window.connect("destroy", gtk.main_quit)

  fixed = gtk.Fixed()
  window.add(fixed)

  app = GuiApp(fixed)

  window.show_all()
  app.show()
  CreateUiComponents(window, app)

def InitPodcasts():
  db.Init()

  subscriptions.Load()
  download.Start()
  #subscriptions.ImportOPML("podcast/podcasts.opml")

def main():
  gobject.threads_init()
  log("main: Call initpodcasts")
  InitPodcasts()
  log("main: call initui")
  InitUi()
  log("main: call gtk.main()")
  gtk.main()
  log("Gtk.main returned.")

if __name__ == "__main__":
  try:
    main()
  except KeyboardInterrupt:
    log("^C")
    sys.exit(1)
  except:
    log("Exception in main thread")
    traceback.print_exc()
    sys.exit(1)
  log("Terminating.")
  sys.exit(1)

